package com.example.mymatch.controller;

import com.example.mymatch.model.User;
import com.example.mymatch.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;  //对某个业务服务的内容进行定义规范  编写者：吴茂景
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制类的实现
 * 编写者：吴茂景
 */
@Api(tags = "用户")
@RestController
public class UserController {

    @Autowired
    private IUserService userService;//对某个业务服务的内容进行定义规范  编写者：吴茂景

    @ApiOperation(value = "查询所有用户信息",notes = "获取用户信息返回json字符串")
    @RequestMapping("/getStr1")
    public String getUser(){
        return "My user";
    }
    @CrossOrigin
    @ApiOperation(value = "对用户信息的添加方法")
    @GetMapping("/addUser")
    public int addUser(User user){
        System.out.println("进入添加用户信息接口");
        return userService.insertUser(user);
    }

    @GetMapping("getAll1")
    @ApiOperation(value = "对用户信息的查询方法")
    public List<User> getAllUser(User user){
        System.out.println("进入查询方法");

        List<User> listUser=userService.getAllUser(user);

        return listUser;
    }

    @PutMapping("/editUser")
    @ApiOperation(value = "对用户信息的修改方法")
    public int EditUser(@RequestBody User user){
        System.out.println("进入用户修改方法");
        return userService.updateUser(user);
    }

    @GetMapping("/delUser")
    @ApiOperation(value = "对用户信息的删除方法")
    public int Delete(String name){
        System.out.println("进入用户删除方法");
        int returnValue=0;
        if (name!=null){
            User user=new User();
            user.setUserName(name);
            returnValue= userService.deleteUser(user);
        }
        return returnValue;
    }

    @GetMapping("/getOne")
    @ApiOperation(value = "对单条用户信息的查询方法")
   public  User getUser(String name){
        User user=new User();
        System.out.println("进入单条查询方法");
        if (name!=null){
            User user1=new User();
            user1.setUserName(name);
            user=userService.getUser(user1);
            System.out.println("返回的数据集合为："+user.getUserName());
        }
        return user;
   }
}
